<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .top {
            border: 1px solid black;
        }
    </style>
    <script type="text/javascript" src="vue.js"></script>

</head>

<body>
    <div id="a" class="top">
        <p>小黑记事本
        </p>
        <input v-on:keyup.enter="jia" type="text " placeholder="请输入 " v-model="messege ">
        <ul>
            <li v-for="(it,index) in shuzu ">{{index+1}}{{it}}&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                <span @click="shanchu(index)">删除 </span>
            </li>

        </ul>
        </br>
        <div class="bottom " v-if="shuzu.length!=0 ">
            有{{shuzu.length}}条 &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp
            <span @click=" cl "> clear</span>
        </div>
    </div>
    <script>
        //1.删除功能：点击事件如何获得index：传参
        //2.清空功能：数组清空直接令数组为【】，不必一个个删
        //3.v-model是相关联不是存储
        //4.数组为0时的隐藏功能：不必在每次操作后判断是否为0，直接v-if=“shuzu.length！=0”

        new Vue({
            el: " #a ",
            data: {
                shuzu: ["hao ", "zai ", "juan "],
                messege: "bmmm ",

            },
            methods: {
                jia: function() {
                    this.shuzu.push(this.messege);
                },

                shanchu: function(index) {

                    this.shuzu.splice(index, 1);
                },
                cl: function() {
                    // for (i = 0; this.shuzu.length > 0;) {
                    //     this.shuzu.splice(i, 1);
                    // }
                    this.shuzu = [];
                }
            }
        })
    </script>


</body>

</html>